$().ready(function(){
    // 事件绑定
    comm_InitPageEvent();
    // 页面初始化
    comm_InitPageInfo();
});

/**
 * 事件绑定
 */
function comm_InitPageEvent(){
	
	$("#loginSubmit").click(LoginForm);
	$("#loginout").click(LoginOut);
	
	$("#searchBtn").click(function(){
		$("#searchForm").submit();
		return false;
	});
	
    $("#loginForm").bind('keyup', function(e){
        if (e.keyCode == 13) {
            LoginForm(e);
        }
    });
}

/**
 * 页面初始化
 */
function comm_InitPageInfo(){
	$("#searchText").val("");
	
	$("#noticeBox").slide({
        mainCell: "ul",
        effect: "topMarquee",
        vis: 6,
        interTime: 40,
        autoPlay: true
    });
	
	$('.top_flexslider').flexslider({
        animation: "slide",
        easing: "easeOutQuad",
        direction: "vertical",
        animationSpeed: 1000,
        directionNav: false,
        start: function(slider){
            $('body').removeClass('loading');
        }
    });
}

function LoginForm(e){
	e.preventDefault();
	$("#loginForm").ajaxSubmit({
		dataType : "json",
		success : function(data) {
			if (!data.success) {
				alert(data.message);
			} else {
				location.reload();
				window.open(serverPath+data.jump);
			}
		}
	});
}

function LoginOut(e){
	e.preventDefault();
	$.post(serverPath + "/action/interact/loginOut", {
		Action : "post"
	}, function(data, textStatus) {
		if (!data.success) {
				alert(data.message);
			} else {
				location.reload();
			}
	}, "json");
}
